/**
 * 
 */
package truerefactor.genetic;

import java.util.List;

import truerefactor.refactor.Refactoring;

/**
 * Allele - The basic element of an individual used by the Genetic Algorithm.
 * This Allele is used to contain a refactoring sequence.
 * 
 * @author Isaac Griffith
 */
public class Allele {

    /**
     * The refactoring sequence represented by this allele
     */
    private List<Refactoring> refactorings;

    /**
     * Creates a new instance of an allele using a copy of the provided allele's
     * refactoring sequence
     * 
     * @param clone
     *            an allele from which this allele is to be cloned
     */
    public Allele(Allele clone)
    {
        refactorings = clone.getRefactoringSequence();
    }

    /**
     * Creates a new instance of an Allele with the provided refactoring
     * sequence
     * 
     * @param refactoring
     *            The sequence of refactorings represented by this Allele
     */
    public Allele(List<Refactoring> refactoring)
    {
        this.refactorings = refactoring;
    }

    /**
     * @return the contained sequence of refactorings in this Allele
     */
    public List<Refactoring> getRefactoringSequence()
    {
        return refactorings;
    }

    /**
     * Sets the contained Refactoring sequence to be the provided list of
     * refactorings
     * 
     * @param refactoring
     *            the new refactoring sequence of this allele
     */
    public void setRefactoringSequence(List<Refactoring> refactoring)
    {
        this.refactorings = refactoring;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    public String toString()
    {
        StringBuilder sb = new StringBuilder();

        for (Refactoring refactoring : refactorings)
            sb.append(refactoring.getName() + ", ");

        return sb.toString();
    }
}
